import { Define, EntityObjectFactory } from 'tiny-entity2';
const EntityObjectType = EntityObjectFactory.GetEntityObjectType(process.env.dataBaseType || 'mysql');
import { Order } from './order';
import { TableWaiters } from './tableWaiters';

@Define.Table({ TableName: "tableservicelog" })
export class TableServiceLog extends EntityObjectType<TableServiceLog>{
    @Define.PrimaryKey()
    id: string;

    @Define.Column({
        DataType: Define.DataType.VARCHAR,
        NotAllowNULL: true
    })
    tableId: string;

    @Define.Column({
        DataType: Define.DataType.VARCHAR,
        NotAllowNULL: true
    })
    tableName: string;

    @Define.Column({
        DataType: Define.DataType.VARCHAR
    })
    tableZoneName: string;

    @Define.Column({
        DataType: Define.DataType.VARCHAR,
        NotAllowNULL: true
    })
    orderId: string;

    @Define.Column({
        DataType: Define.DataType.BIGINT
    })
    openedTime: number;

    @Define.Column({
        DataType: Define.DataType.BIGINT
    })
    closedTime: number;

    @Define.Column({
        DataType: Define.DataType.BIGINT
    })
    cleanTime: number;

    @Define.Column({
        DataType: Define.DataType.VARCHAR
    })
    refServiceId: string;

    @Define.Column({
        DataType: Define.DataType.BOOL
    })
    isGroup: boolean;

    @Define.Column({
        DataType: Define.DataType.BOOL
    })
    isCurrent: boolean;

    @Define.Column({
        DataType: Define.DataType.VARCHAR,
        NotAllowNULL: true,
        DefaultValue: 'opening'
    })
    status: string;

    @Define.Column({
        DataType: Define.DataType.INT,
        DataLength: 10,
        DefaultValue: 0
    })
    customerCount: number;

    @Define.Column({
        DataType: Define.DataType.VARCHAR
    })
    lock: string;

    @Define.Column({
        DataType: Define.DataType.VARCHAR,
        NotAllowNULL: true,
        IsIndex: true
    })
    storeId: string;

    @Define.Column({
        DataType: Define.DataType.BIGINT
    })
    version: number;

    @Define.Mapping({
        Mapping: 'Order',
        MappingKey: { FKey: 'id', MKey: 'orderId' },
        MappingType: Define.MappingType.One
    })
    order: Order;

    @Define.Mapping({
        Mapping: 'TableWaiters',
        MappingKey: 'tableServiceId'
    })
    tableWaiters: TableWaiters[];


    groupItems: TableServiceLog[];
}

export const TableServiceLogStatus = {
    Opening: 'opening',
    Closed: 'closed',
    Cleaning: 'cleaning',
    Merged: 'merged',
    Settlement: 'settlement'
}